<?php //ver.2011 0.1 - Eugenio Ghiglia <eugenio@blux.org> -
session_start(); 
$q=str_replace('%','',trim($_GET['q']));

$_title='Cerca '.(($q)?str_replace('"','',$q):'annunci').' su '.$_SERVER['SERVER_NAME'];
$_keywords=_annunci_get_canali_list();
$_description='Cerca annunci nei canali: '._annunci_get_canali_list();

$html='<form method="get" action="cerca.html" id="search_page_form">
            <div>
                <input type="text" name="q" id="search-text" value="'.htmlspecialchars($q).'" />
                <input type="submit" id="search-submit" value="TROVA" />
            </div>
        </form>';
        
if ($q && strlen($q)>3) {        
    $sql="SELECT * FROM tbl_annunci 
           WHERE attivo='1'
             AND scaduto='0'
             AND descrizione like '%".addslashes(str_replace(' ','%',$q))."%'
            ORDER by data_pubblicazione_online ASC";
    $db->sql_arr($sql, $record, $n);        
    if ($n) {
        for ($i=0;$i<$n;$i++) {
    	    $testo=htmlspecialchars($record[$i]['descrizione']);
            $testo=str_replace('[b]','<strong>',$testo);
            $testo=str_replace('[/b]','</strong>',$testo);
            $testo=str_replace('[u]','<u>',$testo);
            $testo=str_replace('[/u]','</u>',$testo);
            $testo='<p>'.$testo.'</strong></u><br/>
                    &gt;&gt; <a href="http://'.$_SERVER['SERVER_NAME'].'/annunci.html?view='.$record[$i]['id_annuncio'].'">http://'.$_SERVER['SERVER_NAME'].'/annunci.html?view='.$record[$i]['id_annuncio'].'</a></p>';
            $html.='<div class="search_result_item">
                        '.$testo.'
                    </div>';
    	}
    } else {
        if ($q) {
            $html.='<p>Nessun risultato trovato</p>';
        }
    }      
}          
        
?>
